package com.lhs.Result;

import lombok.Builder;
import lombok.Data;

import java.io.Serializable;

@Data
@Builder
public class ResultCode implements Serializable {


    private static final long serialVersionUID = -6269841958947880397L;

    /**
     * 状态码
     */
    private int code;

    /**
     * 状态信息
     */
    private String msg;

    // --- 成功状态码 (2xx) ---
    /**
     * 默认成功
     */
    public final static ResultCode SUCCESS = dispose(ResultCodeEnum.SUCCESS);
    /**
     * 默认失败
     */
    public final static ResultCode ERROR = dispose(ResultCodeEnum.ERROR);

    /** 创建成功 */
    public static final ResultCode CREATED = dispose(ResultCodeEnum.CREATED);

    /** 更新成功 */
    public static final ResultCode UPDATED = dispose(ResultCodeEnum.UPDATED);

    /** 删除成功 */
    public static final ResultCode DELETED = dispose(ResultCodeEnum.DELETED);








    // --- 客户端错误状态码 (4xx) ---
    /**
     * 请求参数错误或语法错误
     */
    public final static ResultCode BAD_REQUEST = dispose(ResultCodeEnum.BAD_REQUEST);
    /**
     * 未授权，要求身份验证
     */
    public final static ResultCode UNAUTHORIZED = dispose(ResultCodeEnum.UNAUTHORIZED);
    /**
     * 服务器理解请求但拒绝执行
     */
    public final static ResultCode FORBIDDEN = dispose(ResultCodeEnum.FORBIDDEN);
    /**
     * 请求的资源不存在
     */
    public final static ResultCode NOT_FOUND = dispose(ResultCodeEnum.NOT_FOUND);
    /**
     * 请求方法不允许用于该资源
     */
    public final static ResultCode METHOD_NOT_ALLOWED = dispose(ResultCodeEnum.METHOD_NOT_ALLOWED);
    /**
     * 请求超时
     */
    public final static ResultCode REQUEST_TIMEOUT = dispose(ResultCodeEnum.REQUEST_TIMEOUT);
    /**
     * 请求与资源的当前状态冲突
     */
    public final static ResultCode CONFLICT = dispose(ResultCodeEnum.CONFLICT);

    // --- 服务器错误状态码 (5xx) ---
    /**
     * 服务器内部错误，无法完成请求
     */
    public final static ResultCode INTERNAL_SERVER_ERROR = dispose(ResultCodeEnum.INTERNAL_SERVER_ERROR);
    /**
     * 服务器不支持实现请求所需的功能
     */
    public final static ResultCode NOT_IMPLEMENTED = dispose(ResultCodeEnum.NOT_IMPLEMENTED);
    /**
     * 服务不可用，可能由于过载或维护
     */
    public final static ResultCode SERVICE_UNAVAILABLE = dispose(ResultCodeEnum.SERVICE_UNAVAILABLE);
    /**
     * 网络超时
     */
    public final static ResultCode GATEWAY_TIMEOUT = dispose(ResultCodeEnum.GATEWAY_TIMEOUT);

    // --- 业务相关状态码 (使用5xx后扩展) ---
    /**
     * 通用业务异常
     */
    public final static ResultCode BIZ_ERROR = dispose(ResultCodeEnum.BIZ_ERROR);
    /**
     * 参数错误
     */
    public final static ResultCode PARAM_ERROR = dispose(ResultCodeEnum.PARAM_ERROR);
    /**
     * 数据不存在
     */
    public final static ResultCode DATA_NOT_FOUND = dispose(ResultCodeEnum.DATA_NOT_FOUND);
    /**
     * 数据已存在
     */
    public final static ResultCode DATA_ALREADY_EXIST = dispose(ResultCodeEnum.DATA_ALREADY_EXIST);
    /**
     * 参数验证失败
     */
    public final static ResultCode VALIDATE_ERROR = dispose(ResultCodeEnum.VALIDATE_ERROR);

    // --- 文件相关状态码 (6xx) ---
    /**
     * 文件超出最大限制
     */
    public final static ResultCode FILE_OUT_MAX = dispose(ResultCodeEnum.FILE_OUT_MAX);
    /**
     * 文件格式不正确
     */
    public final static ResultCode FILE_FORMAT_ERROR = dispose(ResultCodeEnum.FILE_FORMAT_ERROR);
    /**
     * 文件不存在
     */
    public final static ResultCode FILE_NOT_FOUND = dispose(ResultCodeEnum.FILE_NOT_FOUND);

    // --- 系统相关状态码 (7xx) ---
    /**
     * Json解析异常
     */
    public final static ResultCode JSON_FORMAT_ERROR = dispose(ResultCodeEnum.JSON_FORMAT_ERROR);
    /**
     * Sql解析异常
     */
    public final static ResultCode SQL_ERROR = dispose(ResultCodeEnum.SQL_ERROR);
    /**
     * 系统异常
     */
    public final static ResultCode SYS_ERROR = dispose(ResultCodeEnum.SYS_ERROR);
    /**
     * 未知的接口
     */
    public final static ResultCode UNKNOWN_INTERFACE = dispose(ResultCodeEnum.UNKNOWN_INTERFACE);
    /**
     * 请求方式不支持
     */
    public final static ResultCode REQ_MODE_NOT_SUPPORTED = dispose(ResultCodeEnum.REQ_MODE_NOT_SUPPORTED);

    /**
     * 根据枚举生成ResultCode对象
     *
     * @param codeEnum 状态码枚举
     * @return ResultCode对象
     */
    private static ResultCode dispose(ResultCodeEnum codeEnum) {
        return ResultCode.builder().code(codeEnum.getCode()).msg(codeEnum.getMsg()).build();
    }

    /**
     * 全参构造函数
     *
     * @param code 状态码
     * @param msg  状态信息
     */
    public ResultCode(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
}